/*
This file is part of Docking@Home.
http://docking.gcl.cis.udel.edu
Copyright (C) 2009 University of Delaware

Docking@Home is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Docking@Home is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Docking@Home.  If not, see <http://www.gnu.org/licenses/>.
*/
//kevin kreiser
//add this set of functionality as well as a lot of other stuff to many other files within this project....
#ifndef _INTERACT_h
#define _INTERACT_h
#include "happyhttp.h"

#ifdef WIN32
	#include <winsock2.h>
	#include <ws2tcpip.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/timeb.h>
#include <time.h>

using namespace std;

//the max length of the news string
const unsigned int TICKER_STR_LEN = 125;
//how long before looking for a news update
const unsigned long UPDATE_FREQ_MS = 5*60000;
//how long before scrolling the tick to the left
const unsigned long TICK_FREQ_MS = 250;
//how long to wait before giving up on a response from the server
const unsigned long DOWNLOAD_TIMEOUT_MS = 2000;

class NewsTicker{

	public:
		NewsTicker(string hostName="docking.cis.udel.edu",string filePath="/ticker.php",int port=80);
		~NewsTicker();
		void Tick(bool force=false);
		char *getNews();

	private:
		static void OnBegin(const happyhttp::Response* r, void *object);
		static void OnData(const happyhttp::Response* r, void *object,const unsigned char* data, int n);
		static void OnComplete(const happyhttp::Response* r, void *object);
		static string between(string source,string start,string end);
		//hold the data
		string page,news,host,file;
		//the actual ticker
		char *ticker;
		//hold the last update time
		time_t updated,ticked;
		//date when the news was last modified
		unsigned long modified;
		//the connection object
		happyhttp::Connection *connection;
		//whether or not we have a connection
		bool connected;
};

#endif
